﻿Imports Aricie.DNN.Modules.LuceneSearch.Settings
Imports System.Xml.Linq
Imports System.Linq
Imports Aricie.DNN.Services.UpgradeSystem
Imports Aricie.DNN.Services.UpgradeSystem.Actions.Settings
Imports Aricie.DNN.Modules.LuceneSearch.Business

Namespace UpgradeSystem
    Public Class UpgradeTo162ActionsProvider
        Implements IUpgradeActionsProvider(Of LuceneSearchController)


        Public Function GetActions() As UpgradeActionsCollection Implements IUpgradeActionsProvider(Of LuceneSearchController).GetActions
            Dim UpgradeTo162 = New UpgradeActionsCollection(New Version(1, 6, 2))

            UpgradeTo162.UpgradeModuleSettingsActions.Add(New UpgradeModuleSettingsAction(Of LuceneResultsSettings) With {.Name = "Suppression du filtre sur les résultats pour les droits utilisateurs", .UpgradeOperation = AddressOf Me.RemoveFilterOnResults})

            Return UpgradeTo162
        End Function


        Private Function RemoveFilterOnResults(TargetVersion As Version, XD As XDocument, ScopeInfo As ScopeInformation) As XDocument
            'supprimons les filtres sur résultats
            Dim PermissionFilterNode = (From nodes In XD.Descendants("PermissionFilter") Select nodes).FirstOrDefault
            If PermissionFilterNode IsNot Nothing Then
                If PermissionFilterNode.Value = "FilterResults" Then
                    PermissionFilterNode.Value = PermissionFilter.FilterQuery.ToString()
                End If
            End If

            Return XD
        End Function

    End Class
End Namespace